// components/ng-navbar/index.js

import i18nInstance from '../../miniprogram_npm/miniprogram-i18n-plus/index'

const app = getApp()

Component({

  properties: {
    title: {
      type: String,
      value: 'Wechat'
    },
    backgroundColor: {
      type: String,
      value: '#f0f0f0'
    },
    type: {
      type: String,
      value: 'default'
    }
  },

  data: {
    statusBarHeight: app.data.systemInfo.statusBarHeight + 'px',
    navigationBarHeight: (app.data.systemInfo.statusBarHeight + 44) + 'px',
    lang: 'zh',
  },
  ready() {
    this.setData({ lang: app.data.lang })
  },
  methods: {
    onBack() {
      const pages = getCurrentPages(); // 获取加载的页面
      console.log(pages,"pages");
      // 没有其他页面的情况下返回首页
      if(pages.length==1){
        wx.reLaunch({
          url: '/pages/home/index',
        })
      }
      const currentPage = pages[pages.length - 1]; // 获取当前页面的对象
      const url = currentPage.route; // 当前页面url
     console.log(url);
      if(url=='subpackages/custom/list/index'){
        wx.reLaunch({
          url: '/pages/custom/index',
        })
        return
      }
      wx.navigateBack()
    },
    changeLang() {
      if (i18nInstance.getLocale() === 'zh') {
        i18nInstance.setLocale('en')
        this.setData({ lang: 'en' })
      } else {
        i18nInstance.setLocale('zh')
        this.setData({ lang: 'zh' })
      }
    },
  }
})